package com.spark.usermusicService.controller;


import com.spark.R;
import com.spark.usermusicService.entity.LoveMusic;
import com.spark.usermusicService.entity.Music;
import com.spark.usermusicService.service.impl.LoveMusicServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 我的喜欢 前端控制器
 * </p>
 *
 * @author wzk
 * @since 2021-07-01
 */
@RestController
@RequestMapping("/usermusicService/lovemusic")
@CrossOrigin
public class LoveMusicController {
    @Autowired
    private LoveMusicServiceImpl loveMusicService;

    @GetMapping("/user/{userId}")
    public R findAllByUserId(@PathVariable("userId") String userId) {
        List<LoveMusic> playlist = loveMusicService.getLoveMusicByUserId(userId);
        return R.ok().data("items", playlist);
    }

    @GetMapping("/{lovemusicId}")
    public R findByLoveMusicId(@PathVariable("lovemusicId") String loveMusicId) {
        LoveMusic loveMusic = loveMusicService.getById(loveMusicId);
        return R.ok().data("items", loveMusic);
    }

    @GetMapping("/delete/{lovemusicId}")
    public R deleteByLoveMusicId(@PathVariable("lovemusicId") String lovemusic_id) {
        boolean removeById = loveMusicService.removeById(lovemusic_id);
        return R.ok();
    }

    @PostMapping("/save")
    public R addLoveMusic(@RequestBody() LoveMusic loveMusic) {
        boolean b = loveMusicService.save(loveMusic);
        return R.ok();
    }

    @GetMapping("/details/user/{userId}")
    public R findAllLoveMusicDetailsByUserId(@PathVariable("userId") String userId) {
        List<Music> musicList = loveMusicService.getLoveMusicDetailsByUserId(userId);
        return R.ok().data("items", musicList);
    }
}

